package com.xyh.controller;

import com.xyh.po.User;
import com.xyh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @Author:kyle
 * @Date:2020/12/23 - 14:00
 * @Project:spring_StudentsDormitoryManagementSystem
 * @Package:com.xyh.controller
 * @Version:1.0
 */
@Controller
public class UserController {

    @Autowired
    private UserService userService;

    //用户登录
    @RequestMapping("/login")
    public String login(String username,String password, HttpSession session){

        User user = userService.login(username, password);
        if(user != null){
            session.setAttribute("user",user);
            return "main";
        }
        else{
            return "error";
        }
    }
}
